﻿using SD.Infrastructure.WPF.Caliburn.Aspects;
using SD.Infrastructure.WPF.Caliburn.Base;
using System.ServiceModel.Extensions;
using System.Threading.Tasks;
using System.Windows;
using SlamDunk.MES.IAppService.Interfaces;

namespace SlamDunk.MES.Client.ViewModels.ExecutionPlanInspection
{
    public class AddItemViewModel : ScreenBase
    {
        #region # 字段及构造器
        /// <summary>
        /// 作业管理服务契约接口代理
        /// </summary>
        private readonly ServiceProxy<IExecutionContract> _iExecutionContract;


        /// <summary>
        /// 依赖注入构造器
        /// </summary>
        public AddItemViewModel(ServiceProxy<IExecutionContract> iExecutionContract)
        {
            this._iExecutionContract = iExecutionContract;
        }

        #endregion

        #region 属性

        #region 产品名称
        /// <summary>
        /// 产品名称
        /// </summary>
        [DependencyProperty]
        public string ExecutionPlanName { get; set; }
        #endregion

        #region 生产数量
        /// <summary>
        /// 生产数量
        /// </summary>
        [DependencyProperty]
        public decimal? ProductionQuantity { get; set; }
        #endregion

        #region 合格数量
        /// <summary>
        /// 合格数量
        /// </summary>
        [DependencyProperty]
        public decimal? QualifiedQuantity { get; set; }
        #endregion

        #region 样品数量
        /// <summary>
        /// 样品数量
        /// </summary>
        [DependencyProperty]
        public decimal? SampleQuantity { get; set; }
        #endregion

        #region 人员工时
        /// <summary>
        /// 人员工时
        /// </summary>
        [DependencyProperty]
        public decimal? Manhour { get; set; }
        #endregion

        #region 设备台时
        /// <summary>
        /// 设备台时
        /// </summary>
        [DependencyProperty]
        public decimal? Machinehour { get; set; }
        #endregion

        #region 备注
        /// <summary>
        /// 备注
        /// </summary>
        [DependencyProperty]
        public string Description { get; set; }
        #endregion


        #endregion

        #region 方法

        #region 加载 —— async Task Load(string executionPlanName)
        /// <summary>
        /// 加载
        /// </summary>
        public async Task Load(string executionPlanName)
        {
            this.ExecutionPlanName = executionPlanName;
        }
        #endregion

        #region 提交 —— async void Submit()
        /// <summary>
        /// 提交
        /// </summary>
        public async void Submit()
        {
            #region # 验证
            if (this.ProductionQuantity == null)
            {
                MessageBox.Show("请输入生产数量！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (this.QualifiedQuantity == null)
            {
                MessageBox.Show("请输入合格数量！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (this.SampleQuantity == null)
            {
                MessageBox.Show("请输入样品数量！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (this.Machinehour == null)
            {
                MessageBox.Show("请输入设备台时！", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            #endregion
            await base.TryCloseAsync(true);
        }
        #endregion
        #endregion
    }
}
